"""
name: 教学案例2 使用ui文件布局
version: 1.0
"""
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog
from ui_example import Ui_Form

class MyDialog(QWidget):

    def __init__(self, parent=None):
        super().__init__(parent)
        self.ui = Ui_Form()
        self.ui.setupUi(self)
        self.ui.textEdit.setPlainText('Hello World!')
        self.ui.textEdit.setReadOnly(True)
        self.line = None  # 创建变量
        
    def on_pushButton_2_pressed(self):
        # 使用变量
        self.line = QInputDialog(self)
        self.line.setWindowTitle('编辑')
        self.line.setLabelText('请输入文本')
        self.line.setOkButtonText('确定')
        self.line.setCancelButtonText('取消')
        self.line.resize(400, 40)
        self.line.textValueChanged.connect(self.ui.textEdit.setPlainText)
        self.line.show()

app = QApplication(sys.argv)
dialog = MyDialog()
dialog.show()
sys.exit(app.exec_())
